IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetInstitutionOrUnitDept]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetInstitutionOrUnitDept]
GO
 
SET QUOTED_IDENTIFIER OFF
GO
/******************************************************************                
* Name:   GetInstitutionOrUnitOrDept                
* Purpose:  Retrieves Institution or unit ordepartment(Not used at present as this feature is removed from custom reports)             
*                
* PARAMETERS(IN)                
* Name          Description                     
* -------------      -------------------------------------------                
* @institutionId     institution id (to fetch the corresponding departments,provided the institution is known)            
* @departmentId      department id (to fetch the corresponding units,provided the institution and departments are known)            
*********************************************************************/             
CREATE procedure dbo.[GetInstitutionOrUnitDept] --240      
(@institutionId int=0         
)            
AS BEGIN            
SET NOCOUNT ON            
if @institutionId = 0          
  BEGIN            
  --brings back the list of Institutions            
   Select [Name], Id        
   from fwkDomainOrganization where ParentOrganizationId =1 and id <> 1            
  END            
else if @institutionId <> 0            
  BEGIN     
  --brings back the list of Dept/units         
   Select [Name], Id        
  from fwkDomainOrganization where institutionId=@institutionId   and id <> @institutionId          
  END      
END   